<?php

namespace app\common\model;

use think\Db;
use think\Model;

/**
 * 订单模型
 */
class Order extends Model
{

    // 表名
    protected $name = 'order';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
 
    public function order_add($order){

    	Db::startTrans();
        // 记录订单信息
        $order_no = $this->orderNo();

        $order['order_no'] = $order_no;
        if($order['pay_type']=='10'){
            $order['pay_status'] = 40;
            $order['pay_time'] = time();
            $order['num'] = 1;
        }
        $add_id = $this->save($order);

        empty($add_id);
        Db::commit();
        return $order_no;
    }

    protected function orderNo()
    {
        return 'WM'.date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    }

}
